package cn.yunhe.controller;

import cn.yunhe.model.User;
import cn.yunhe.service.IUserService;
import com.github.pagehelper.Page;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class UserController {

    @Resource
    private IUserService userService;

    @RequestMapping("/userlist")
    public String findAll(Model model) {
        List<User> list = userService.selectAll();
        model.addAttribute("list", list);
        return "list";
    }

    @RequestMapping("/getPage")
    public Map queryUsersByPage(int pageNum, int pageSize, User user) {
        Map map = new HashMap();
        map.put("pageSize", pageSize);
        map.put("pageNum", pageNum);
        map.put("user", user);
        Page page = userService.queryLikeUsers(map);
        map.put("page", page);
        map.put("totalPage", page.getPages());
        return map;
    }


    public IUserService getUserService() {
        return userService;
    }

    public void setUserService(IUserService userService) {
        this.userService = userService;
    }
}
